package com.demo.network.nio;

public class Client {
    private static String DEFAULT_HOST = "127.0.0.1";
    private static int DEFAULT_PORT = 9096;
    private static ClientHandle clientHandle;

    public static void start() {
        start(DEFAULT_HOST, DEFAULT_PORT);
    }

    public static synchronized void start(String ip, int port) {
        if (clientHandle != null) clientHandle.stop();
        clientHandle = new ClientHandle(ip, port);
        new Thread(clientHandle, "Sever").start();
    }


    public static boolean sendMsg(String msg) throws Exception {
        if (msg.equals("q")) return false;
        System.out.println("client start send msg "+msg);
        clientHandle.sendMsg(msg);
        return true;
    }
}
